package com.lc.luzhengtang.activity;

import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;

import com.lc.luzhengtang.BaseApplication;
import com.lc.luzhengtang.R;
import com.lc.luzhengtang.base.BaseActivity;
import com.lc.luzhengtang.bean.CommenBean;
import com.lc.luzhengtang.conn.ConnChangeQq;
import com.lc.luzhengtang.util.LovelyToast;
import com.lc.luzhengtang.util.RegexValidateUtil;
import com.zcx.helper.http.AsyCallBack;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * Created by Administrator on 2017/5/11.
 */
public class BindWxActivity extends BaseActivity {


    @BindView(R.id.img_news)
    ImageView imgNews;
    @BindView(R.id.text_submit)
    TextView textSubmit;
    @BindView(R.id.edittext_nickName)
    EditText edittextNickName;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_bindwx);
        ButterKnife.bind(this);
    }

    @Override
    protected void onResume() {
        super.onResume();
        edittextNickName.setText(BaseApplication.basePreferences.readQq());
    }


    @OnClick({R.id.img_news, R.id.text_submit, R.id.edittext_nickName})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.img_news:
                finish();
                break;
            case R.id.text_submit:
                if (TextUtils.isEmpty(edittextNickName.getText().toString().trim())) {
                    LovelyToast.makeText(BindWxActivity.this, "QQ不能为空", 0, LovelyToast
                            .SUCCESS, LovelyToast.SCALE);
                } else if (!RegexValidateUtil.isQQCorrect(edittextNickName.getText().toString().trim())) {
                    LovelyToast.makeText(BindWxActivity.this, "您输入的qq号码不正确", 0, LovelyToast
                            .SUCCESS, LovelyToast.SCALE);
                } else {
                    ConnChangeQq();
                }

                break;
            case R.id.edittext_nickName:
                break;
        }
    }

    public void ConnChangeQq() {
        new ConnChangeQq(BaseApplication.basePreferences.readUid(), edittextNickName.getText().toString().trim(), new AsyCallBack<CommenBean>() {
            @Override
            public void onSuccess(String toast, int type, Object o, CommenBean changeNickName) throws Exception {
                super.onSuccess(toast, type, o, changeNickName);
                LovelyToast.makeText(BindWxActivity.this, changeNickName.getMessage(), 0, LovelyToast
                        .SUCCESS, LovelyToast.SCALE);
                BaseApplication.basePreferences.saveQq(edittextNickName.getText().toString().trim());
                finish();
            }

            @Override
            public void onFail(String toast, int type) throws Exception {
                super.onFail(toast, type);

            }

            @Override
            public void onEnd(String toast, int type) throws Exception {
                super.onEnd(toast, type);
            }
        }

        ).execute(BindWxActivity.this, false);
    }


}
